/**
 *  编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-10 20:12:58
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        laydate = layui.laydate,
        $view = $('#resource-stop'),

        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (resourceData) {
            form.val("resource-stop-form", {
                "id": resourceData.id,
                // "rsNo": resourceData.rsNo,
                // "rsName": resourceData.rsName,
                // "rsType": resourceData.rsType,
                // "rsPlace": resourceData.rsPlace,
                // "rsDirector": resourceData.rsDirector,
                // "rsStatus": resourceData.rsStatus,
            });
        }
    }

    form.on('submit(resource-stop-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        febs.modal.confirm("停用提示！","是否停用？",function (index){
            if (data.id && data.id.length > 0) {
                febs.postArray(ctx + 'resource/stop', data, function () {
                    layer.closeAll();
                    febs.alert.success('停用成功');
                    $('#febs-resource').find('#query').trigger('click');
                });
            }
        });
    }

    laydate.render({
        elem: "#stopStartTime",
        format: 'yyyy-MM-dd HH:mm',
        done: function (value, date) {
            if ($("#stopEndTime").val() && value > $("#stopEndTime").val()) {
                febs.alert.warn('开始时间不能大于结束时间');
                $("#stopStartTime").val("");
            }
        },
    });

    laydate.render({
        elem: "#stopEndTime",
        format: 'yyyy-MM-dd HH:mm',
        done: function (value, date) {
            if ($("#stopStartTime").val() && value < $("#stopStartTime").val()) {
                febs.alert.warn('结束时间不能小于开始时间');
                $("#stopEndTime").val("");
            }
        },
    });
});